<!-- 任务头部信息组件 -->
<template>
  <view class="task-header">
    <image 
      :src="getAvatarUrl(task?.userAvatar)" 
      mode="aspectFill" 
      class="user-avatar" 
      @error="handleTaskAvatarError" 
    />
    <view class="header-main">
      <view class="header-title-row">
        <text class="task-title">{{ task?.title }}</text>
        <view class="status-tag">
          <text>{{ getStatusText(task?.status) }}</text>
        </view>
      </view>
      <view class="task-publisher">
        发布者：{{ task?.userName || '未知用户' }} ({{ task?.orgName || '未知企业' }})
      </view>
      <view class="task-time">发布时间：{{ task?.publishTime }}</view>
      <view class="task-deadline">截止日期：{{ task?.deadline }}</view>
    </view>
  </view>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'
import { NETWORK_CONFIG } from '@/config/network.js'

// Props
const props = defineProps({
  task: {
    type: Object,
    default: () => null
  }
})

// Emits
const emit = defineEmits(['avatar-error'])

// 获取头像URL
const getAvatarUrl = (avatarUrl) => {
  if (!avatarUrl) return '/static/images/default-avatar.png'
  if (avatarUrl.startsWith('http')) return avatarUrl
  return `${NETWORK_CONFIG.API_BASE_URL}${avatarUrl}`
}

// 获取状态文本
const getStatusText = (status) => {
  const statusMap = {
    '0': '待接取',
    '1': '进行中',
    '2': '已完成',
    '3': '已取消',
    '4': '已过期'
  }
  return statusMap[status] || '未知状态'
}

// 处理头像错误
const handleTaskAvatarError = () => {
  emit('avatar-error')
}
</script>

<style scoped>
.task-header {
  display: flex;
  padding: 20rpx;
  background: #fff;
  border-radius: 16rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}

.user-avatar {
  width: 80rpx;
  height: 80rpx;
  border-radius: 50%;
  margin-right: 20rpx;
  flex-shrink: 0;
}

.header-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.header-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10rpx;
}

.task-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
  flex: 1;
  margin-right: 20rpx;
}

.status-tag {
  background: #4CAF50;
  color: white;
  padding: 8rpx 16rpx;
  border-radius: 20rpx;
  font-size: 24rpx;
}

.task-publisher,
.task-time,
.task-deadline {
  font-size: 28rpx;
  color: #666;
  margin-bottom: 8rpx;
}

.task-deadline {
  color: #ff6b6b;
  font-weight: 500;
}
</style>
